using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.ComponentModel;
namespace AppToolKit.Model
{
	[Serializable]
    public abstract class EntityBase : IEntity, INotifyPropertyChanged
	{
        //private ModelDataVerion version_;
		private IEntityFactory factory_;
        public event EventHandler<PropertyChangeEventArgs> PropertyChange;
        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
		public IEntityFactory Factory
		{
			get
			{
				return this.factory_;
			}
			set
			{
				this.factory_ = value;
			}
		}
		public abstract object Key
		{
			get;
		}
		public void RaisePropertyChang(string property, object value)
		{
			if (this.PropertyChange != null)
			{
				PropertyChangeEventArgs propertyChangeEventArgs = new PropertyChangeEventArgs();
				propertyChangeEventArgs.Property = property;
				propertyChangeEventArgs.Value = value;
				this.PropertyChange(this, propertyChangeEventArgs);
			}
		}
		public object Clone()
		{
			MemoryStream memoryStream = new MemoryStream();
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			memoryStream.Position = 0L;
			binaryFormatter.Serialize(memoryStream, this);
			memoryStream.Position = 0L;
			return binaryFormatter.Deserialize(memoryStream);
		}

      
    }
}
